import React from 'react';
import { BrowserRouter as Router, Link, Route, Redirect, Switch } from 'react-router-dom';
import Home from './views/home';
import Users from './views/users';
import About from './views/about';
import NotFound from './views/not-found';

export default function App() {
  return (
    <Router>
      <div>
        <Link to="/home">首页</Link>
        <Link to="/users">用户管理</Link>
        <Link to="/about">关于</Link>
      </div>
      <div>
        <Switch>
          <Route path="/home" component={Home} />
          <Route path="/user" component={Users} />
          <Route path="/about" component={About} />
          <Route path="/404" component={NotFound} />
          {/* 根目录重定向到首页 */}
          <Redirect to="/home" from="/" exact />
          {/* 所有未匹配的地址重定向到404 */}
          <Redirect to="/404" />
        </Switch>
      </div>
    </Router>
  );
}
